<?php
include '../include/functions.php';
//set session save path
  session_save_path("../$session_path");
  // Initialize a session. 
  session_start(  );
            //session_destroy();             
  $count++;                         
  $sessionId = session_id();
//Connect To Database
dbConnect();
if($userID != "")
{
	$SQL = "SELECT Username FROM NFLUsers WHERE ID=$userID";
	$result = mysql_query($SQL) or die("Cannot query the database.<br>" . mysql_error());
	$myrow = mysql_fetch_array($result);
	$username = $myrow["Username"];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//Dtd html 4.01 Transitional//EN"
"http://www.w3.org/tr/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/MAIN.dwt.php" codeOutsideHTMLIsLocked="false" -->
  <head>
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>JoshHughes.com NFL Football Pool</title>
    <!-- InstanceEndEditable -->
	<link rel="stylesheet" href="../css/football.css" type="text/css">
    <script src="../scripts/prototype.js" type="text/javascript"></script>
	<script src="../scripts/scriptaculous.js" type="text/javascript"></script>
	<script type="text/javascript">
	// Dynamic Iframe loader
	function loadIframe(theFrame, theURL) {
		document.getElementById(theFrame).src=theURL;
	}
	
	// resizes Iframe according to content
	function resizeMe(obj){ 
	docHeight = mainContent.document.body.scrollHeight
	 obj.style.height = docHeight + 'px'
	 } 
	</script>
    <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
  </head>
<body>
<div id="pagewidth" >
	<div id="header" >
	
		<?PHP include_once("../layout/header.html"); ?>
		
	</div>
			<div id="wrapper" class="clearfix" > 
			<div id="maincol" >

			<!-- InstanceBeginEditable name="Contents" -->
			<?php

				$js="\nfunction smilie(emote)\n {\n document.reply.comments.value += emote;\n document.reply.comments.focus();\n}\n";
				require_once("config.inc.php");
				require_once("mysql.php");
				require_once("tags.php");
				require_once("censorship.php");
				if (isset($username)) {
				  if (isset($_POST['comments'])) {
					$check = mysql_result(mysql_query("SELECT COUNT(*) FROM tinybb_posts WHERE id='$_POST[id]' AND author='$username'"),0);
					if ($check == 1) {
					  $sql="SELECT topicid FROM tinybb_posts WHERE id='$_POST[id]'";
					  $result=mysql_query($sql);
					  $row = mysql_fetch_array($result);
					  $topicid=$row[topicid];
					  $sql="SELECT * FROM tinybb_posts WHERE id='$_POST[id]' AND author='$_POST[Username]'";
					  $result=mysql_query($sql);
					  while ($row = mysql_fetch_array($result)) {
						$lasthour = time()-3601;
						if ($row[date] > $lasthour) {
						  $comments=strip_tags($_POST[comments],$allowedtags);
						  foreach ($banlist as $word) {
							$count=strlen($word);
							$i=0;
							while ($i < $count) {
							  $replace .= "*";
							  $i++;
							}
							$comments=str_replace($word,$replace,$comments);
							unset($replace,$count);
						  }
						  $now = time();
						  $now_time=date("H:i.s",$now);
						  $comments .= "\n\n- edited at $now_time by $_POST[Username].";
						  $sql="UPDATE tinybb_posts SET text='$comments' WHERE id='$_POST[id]' AND author='$_POST[Username]'";
						  mysql_query($sql);
							?>
							<SCRIPT LANGUAGE="JavaScript">window.location="topic.php?id=<?= $topicid; ?>";</script>
							<?
						}
						else {
						  require_once("headers.php");
						  echo "<p><b>Posts cannot be edited more than an hour after it has been posted.</b></p>\n<p>Please <a href=\"javascript:history.go(-1)\">go back</a> and try again.</p>\n";
						}
					  }
					}
					else {
					  require_once("headers.php");
					  echo "<p><b>This post could not be verified as belonging to you.</b></p>\n<p>Please <a href=\"javascript:history.go(-1)\">go back</a> and try again.</p>\n";
					}
				  }
				  else {
					require_once("headers.php");
					if (isset($_GET['id'])) {
					  $check = mysql_result(mysql_query("SELECT COUNT(*) FROM tinybb_posts WHERE id='$_GET[id]' AND author='$username'"),0);
					  if ($check == 1) {
						$sql="SELECT date, text, topicid FROM tinybb_posts WHERE id='$_GET[id]'";
						$result=mysql_query($sql);
						while ($row = mysql_fetch_array($result)) {
						  $lasthour = time()-3601;
						  if ($row[date] > $lasthour) {
							$comments=$row[text];
							$topicid=$row[topicid];
							echo "<a href=\"topic.php?id=$topicid\" class=\"permLink\">Back To Topic Home</a><br/><form name=\"reply\" action=\"edit.php\" method=\"post\">
					<p>
						<b class=\"nonpost\"><label for=\"comments\">Edit your message below and click submit:</label></b><br />
						The only allowed html tags are $allowedtagshtml
						<br /><br /><b class=\"nonpost\">Add smilies:</b><br />\n";
							foreach ($smilies as $emote) {
							  echo "		<a href=\"#post\" onclick=\"smilie(' [$emote] '); return false;\"><img border=\"0\" src=\"_images/smilies/$emote.gif\" alt=\"$emote\" /></a>&nbsp; \n";
							}
							echo "	</p>
					<textarea name=\"comments\" id=\"comments\" cols=\"52\" rows=\"8\">$comments</textarea><br /><br />
					<input type=\"hidden\" name=\"id\" value=\"$_GET[id]\" />
					<input type=\"hidden\" name=\"topicid\" value=\"$topicid\" />
					<input type=\"image\" class=\"clear\" src=\"_images/form_submit.gif\" />
				</form>\n";
						  }
						  else {
							echo "<p><b>Posts cannot be edited more than an hour after it has been posted.</b></p>\n<p>Please <a href=\"javascript:history.go(-1)\">go back</a> and try again.</p>\n";
						  }
						}
					  }
					  else {
						echo "<p><b>This post could not be verified as belonging to you.</b></p>\n<p>Please <a href=\"javascript:history.go(-1)\">go back</a> and try again.</p>\n";
					  }
					}
				  }
				}
				else {
				  require_once("headers.php");
				  echo "<p><b class=\"nonpost\">You are not currently logged in.</b></p>\n<p>Please <a href=\"javascript:history.go(-1)\">go back</a> and try again.</p>\n";
				}
				
				require_once("footers.php");
				?>
			<!-- InstanceEndEditable -->
			
			</div>
			<div id="leftcol" >
			
				<?PHP include_once("../layout/left_column.php"); ?>
		
			</div>
			
		</div>
		
		<div id="footer" >
		
			<?PHP include_once("../layout/footer.html"); ?>
			
		</div>
</div>
</body>
<!-- InstanceEnd --></html>